<template>
	<view class="fui-wrap">
		<fui-sticky>
			<view style="background-color: #fff;">
				<fui-segmented-control @click="changeSegmented" :current="current" color="#000" activeColor="#0a8cdd" type="text" :values="segmented"></fui-segmented-control>
			</view>
		</fui-sticky>
		<fui-list>
			<fui-list-cell :highlight="false" v-for="(item,index) in list" arrow :key="index" :arrow="false" arrow-color="#fff">
				<block v-if="current===0">
					<view class="ritem">
						<view :class="lineClass">
							<plateType :plate_number="item.records.plate_number" :plate_type="item.records.plate_type"></plateType>
						</view>
						<view :class="lineClass">
							<fui-text :text="`账单时间：${item.createtime}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`停车费用：￥${item.records.total_fee}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`入场时间：${item.records.entry_time_txt}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`减免金额：￥${item.records.activities_fee}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`离场时间：${item.records.exit_time_txt}`" size="24" block></fui-text>
						</view>
					</view>
				</block>
				<block v-if="current===1">
					<view class="ritem" v-if="item.merch.settle_type=='before' || item.merch.settle_type=='after'">
						<view :class="lineClass">
							<fui-text :text="`交易前：￥${item.before}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`时间：${item.createtime}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`变化数：￥${item.change}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`交易类型：${log_type[item.log_type]}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`交易后：￥${item.after}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass" style="height: auto;width: 100%;">
							<fui-text :text="`备注：${item.remark}`" size="24" block></fui-text>
						</view>
					</view>
					<view class="ritem" v-if="item.merch.settle_type=='time'">
						<view :class="lineClass">
							<view class="rx">
								<fui-text text="交易前：" size="24"></fui-text>
								<merch-balance :size="24" :balance="parseNumber(item.before)" :settle_type="item.merch.settle_type"></merch-balance>
							</view>
						</view>
						<view :class="lineClass">
							<fui-text :text="`时间：${item.createtime}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<view class="rx">
							<fui-text text="变化数：" size="24" block></fui-text>
							<merch-balance :size="24" :balance="parseNumber(item.change)" :settle_type="item.merch.settle_type"></merch-balance>
							</view>
						</view>
						<view :class="lineClass">
							<fui-text :text="`交易类型：${log_type[item.log_type]}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<view class="rx">
							<fui-text text="交易后：" size="24" block></fui-text>
							<merch-balance :size="24" :balance="parseNumber(item.after)" :settle_type="item.merch.settle_type"></merch-balance>
							</view>
						</view>
						<view :class="lineClass" style="height: auto;width: 100%;">
							<fui-text :text="`备注：${item.remark}`" size="24" block></fui-text>
						</view>
					</view>
				</block>
				<block v-if="current===2">
					<view class="ritem" v-if="item.merch.settle_type=='before' || item.merch.settle_type=='after'">
						<view :class="lineClass" style="width: 45%;">
							<fui-text :text="`时间：${item.createtime}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass" style="width: 55%;">
							<fui-text :text="`充值金额：￥${item.change}`" size="24" block></fui-text>
						</view>		
						<view :class="lineClass" style="width: 45%;">
							<fui-text :text="`支付方式：${item.payunion.pay_type_text}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass" style="width: 55%;">
							<fui-text :text="`单号：${item.payunion.out_trade_no || '无'}`" size="24" block></fui-text>
						</view>
					</view>
					<view class="ritem" v-if="item.merch.settle_type=='time'">
						<view :class="lineClass">
							<fui-text :text="`充值额度：${parseInt(item.change)}分钟`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`时间：${item.createtime}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`支付金额：￥${item.payunion.pay_price}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`支付方式：${item.payunion.pay_type_text}`" size="24" block></fui-text>
						</view>
						<view :class="lineClass">
							<fui-text :text="`单号：${item.payunion.out_trade_no || '无'}`" size="24" block></fui-text>
						</view>
					</view>
				</block>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<list-filter ref="listfilter" :show-button="(platform=='PC')?false:true" :param="param" @confirm="doSubmit"></list-filter>
		<pcfooter :search="true" @search="showSearch"></pcfooter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDate,formatDateTime,parseNumber} from '@/utils/util.js';
	import plateType from '@/components/common/platetype.vue';
	import listfilter from '@/components/common/filter.vue';
	import merchBalance from '@/components/common/merch-balance.vue';
	import pcfooter from '@/components/common/pcfooter.vue';
	export default {
		components:{
			plateType:plateType,
			listFilter:listfilter,
			merchBalance:merchBalance,
			pcfooter:pcfooter
		},
		data() {
			return {
				baseUrl:baseUrl,
				segmented:['消费账单','余额流水','充值记录'],
				type:['bill','balance','recharge'],
				log_type:{
					admin:'管理员充值',
					recharge:'用户充值',
					records:'停车消费'
				},
				current:0,
				page:1,
				endData:false,
				list:[],
				param:{
					plate_number:'',
					starttime:'',
					endtime:''
				},
				platform:'',
				lineClass:'line'
			}
		},
		onLoad(e) {
			this.$platform();
			if(this.platform=='PC'){
				this.lineClass='line-pc';
			}
			this.getCouponList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getCouponList(function(){
				uni.stopPullDownRefresh();
			});
		},
		onReachBottom() {
			this.getCouponList();
		},
		methods: {
			...methods,
			parseNumber,
			changeSegmented:function(e){
				this.current=e.index;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getCouponList();
			},
			getCouponList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('merchant/bill/list',{
					type:this.type[this.current],
					...this.param,
					platform:this.platform,
					page:this.page
				},true).then(res=>{
					res.map(t=>{
						if(t.payunion){
							t.remark+="，实际支付￥"+t.payunion.pay_price;
						}
						return t;
					});
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			},
			formatDateTime:function(e){
				let r=formatDateTime(new Date(e*1000));
				return r.slice(0,16);
			},
			showSearch:function(){
				this.$refs.listfilter.show();
			},
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getCouponList();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fui-cell__arrow{
		display: none;
	}
	.fui-wrap{
		padding-top: 0rpx;
	}
	.ritem{
		width: 100%;
		display: flex;
		flex-wrap: wrap;
	}	
	.line{
		height: 60rpx;
		line-height: 60rpx;
		width: 50%;
		.rx{
			display: flex;
		}
	}
	.line-pc{
		width: 20%;
		margin-bottom: 20rpx;
		.rx{
			display: flex;
		}
	}
</style>